export default{
	data(){
		return {
			baseData:[],
			modal1:false,
			ids:[],//多选
			istrue:true,
			formValidate:{
                	title:"",
                	type:1,
//              	parentId:null
                }
		}
	},
	methods:{
		//
		changeType(type){
        		this.formValidate.type=type;
        		this.getTree(this.formValidate.type)
        },
		//修改节点
		updateChange(){
			this.ids.forEach((element)=>{
				console.log(element)
				this.$http({
	        		method:'post',
	        		url:`http://localhost:3000/${this.module1}/data/`+element._id,
	        		data:this.formValidate
	        }).then((response)=>{	
	        		this.formValidate.title=""
	        		this.getTree(this.formValidate.type)
	        	})	
			}) 
		},
		//取得父节点的ID
		getParentId(){
			this.ids.forEach((element)=>{
				this.formValidate.parentId=element._id;
			})
		},	
		//添加子节点
		onAddChange(){
			this.getParentId()
			if(this.formValidate.parentId !=''){				
				this.$http({
	        		method:'post',
	        		url:`http://localhost:3000/${this.module1}/data`,
	        		data:this.formValidate
	        }).then((response)=>{
	        		console.log(response)
	        		console.log(this.formValidate)
	        		this.changeType(this.formValidate.type);
		        	this.getTree(this.formValidate.type)
	        	})	
			}		        	
		},		
		//删除根节点
        onCheckChange(ids){
        	this.ids=ids; 
//      	console.log(ids)
			this.getarr()
        },
        onChanges(){
        	this.ids.forEach((element)=>{     	
        		this.$http({
	        		method:'delete',
	        		url:`http://localhost:3000/${this.module1}/data/`+element._id,	        		
	        	}).then((response)=>{	
	        		this.getTree(this.formValidate.type)
	        	})	
        	})       	
        },
        //添加根节点
        onadd(){
        	 this.$http({
				method:"POST",
				url:`http://localhost:3000/${this.module1}/data`,
				data:this.formValidate
			})
			.then(res=>{
//				console.log(res)
				this.getTree(this.formValidate.type)
			})
        },
       	getTree(type){
    		this.$http({
        		url:`http://localhost:3000/${this.module1}/list/`+type,
        		method:"get"
        }).then(res=>{
        		this.baseData=res.data
        	})
    	}
	},
    created(){
    	this.getTree(1)
    }
}
